package org.hnxxxy.ebms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.hnxxxy.ebms.common.Result;
import org.hnxxxy.ebms.pojo.Admission;
import org.hnxxxy.ebms.mapper.AdmissionMapper;
import org.hnxxxy.ebms.pojo.Student;
import org.hnxxxy.ebms.pojo.TeacherAdmiss;
import org.hnxxxy.ebms.service.AdmissionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.hnxxxy.ebms.service.StudentService;
import org.hnxxxy.ebms.service.TeacherAdmissService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author WANGWEI
 * @since 2021-06-10
 */
@Service
public class AdmissionServiceImpl extends ServiceImpl<AdmissionMapper, Admission> implements AdmissionService {

    @Autowired
    private TeacherAdmissService teacherAdmissService;

    @Autowired
    private StudentService studentService;

    @Override
    public boolean delById(Integer id) {
        QueryWrapper<TeacherAdmiss> teacherAdmissQueryWrapper = new QueryWrapper<>();
        teacherAdmissQueryWrapper.eq("admission_id",id);
        TeacherAdmiss one = teacherAdmissService.getOne(teacherAdmissQueryWrapper);
        if (one == null){
            QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("admission_id",id);
            if (studentService.getOne(queryWrapper) == null) {
                return removeById(id);
            }
        }
        return false;
    }
}
